<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use backend\assets\FancyBoxAsset;
FancyBoxAsset::register($this);

/* @var $this yii\web\View */
/* @var $model common\models\business\BusinessFarmers */

$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Business Farmers', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>


<section class="wrapper site-min-height">
    <!-- page start-->
    <section class="panel">
        <header class="panel-heading">
              <?= Html::a('返回','javascript:history.back(-1)'); ?>  <?= Html::encode($this->title) ?>
        </header>
        <div class="panel-body">
            <div class="adv-table editable-table ">

                <div class="business-farmers-view">

                    <p>
                        <?= Html::a('更新', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
                        <?= Html::a('删除', ['delete', 'id' => $model->id], [
                            'class' => 'btn btn-danger',
                            'data' => [
                                'confirm' => '您确定删除此项吗?',
                                'method' => 'post',
                            ],
                        ]) ?>
                    </p>

                    <?= DetailView::widget([
                        'model' => $model,
                        'attributes' => [
                            'id',
//                            'no',
                            'gender',
                            'name',
                            'lng',
                            'lat',
                            [
                                'attribute'=>'countyid',
                                'value'=>function($model){
                                    return !$model->county?'':$model->county->name;
                                }
                            ],
                            [
                                'attribute'=>'townid',
                                'value'=>function($model){
                                    return !$model->town?'':$model->town->name;

                                }
                            ],
                            [
                                'attribute'=>'villageid',
                                'value'=>function($model){
                                    return !$model->village?'':$model->village->name;

                                }
                            ],
                            'address',

                            'phone',
                            [
                                'attribute'=>'introducer',
                                'value' => function($model){
                                    return $model->person?$model->person->name:'';
                                }
                            ],
                            [
                                'attribute'=>'status',
                                'value' => function($model){
                                    return \common\models\business\BusinessFarmers::$statues[$model->status];
                                }
                            ],

                            [
                                'attribute'=>'identity_photo',
                                'format'=>'raw',
                                'value'=>function($model){
                                    $html = '';
                                    $ps = \common\components\Upload::checkGetUrl($model->identity_photo,true,'identity_photo');
                                    foreach ($ps as $key => $row){
                                        $html .= "<a class='fancybox' rel='identity_photo' href='{$row}'>".yii\helpers\Html::img(\common\components\Upload::checkGetUrl($row),['alt' => '缩略图','width' => 100 ,'height' => 100,'style'=>'margin-right:10px;']).'</a>';
                                    }
                                    return $html;
                                }
                            ],
                            [
                                'attribute'=>'pighousephoto',
                                'format'=>'raw',
                                'value'=>function($model){
                                    $html = '';
                                    $ps = \common\components\Upload::checkGetUrl($model->pighousephoto,true,'pighousephoto');
                                    foreach ($ps as $key => $row){
                                        $html .= "<a class='fancybox' rel='pighousephoto' href='{$row}'>".yii\helpers\Html::img(\common\components\Upload::checkGetUrl($row),['alt' => '缩略图','width' => 100 ,'height' => 100,'style'=>'margin-right:10px;']).'</a>';
                                    }
                                    return $html;
                                }
                            ],
                            [
                                'attribute'=>'photo',
                                'format'=>'raw',
                                'value'=>function($model){
                                    $html = '';
                                    $ps = \common\components\Upload::checkGetUrl($model->photo,true,'photo');
                                    foreach ($ps as $key => $row){
                                        $html .= "<a class='fancybox' rel='photo' href='{$row}'>".yii\helpers\Html::img(\common\components\Upload::checkGetUrl($row),['alt' => '缩略图','width' => 100 ,'height' => 100,'style'=>'margin-right:10px;']).'</a>';
                                    }
                                    return $html;
                                }
                            ],
                            [
                                'attribute'=>'pigs',
                                'format'=>'raw',
                                'value'=>function($model){
                                    $html = '';
                                    foreach ($model->pigs as $key => $row){
                                        $html .= Html::label($row->no,'',['class'=>'btn btn-default btn-xs','style'=>'margin-right:10px;']);
                                    }
                                    return $html;
                                }
                            ],
                        ],
                    ]) ?>

                </div>
            </div>
        </div>
    </section>
</section>


<script>
    <?php $this->beginBlock('js_end') ?>
    //点击预览图片
    $('.fancybox').fancybox({
        'titlePosition' : 'over',
        'cyclic'        : true,
        'height':500
    });
    <?php $this->endBlock(); ?>
    <?php $this->registerJs($this->blocks['js_end'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>

</script>
